#include "aga.h"

//! Percentuale degli individui tra i quali individui ricercare il primo genitore
#define FIRST_PARENT 0.5

#if (PHASES==1)
//#warning genetic_mospk compilato per 1 fase

#define PHASE_0_TOTAL_COST	0.95
#define PHASE_0_VEHICLES_NUMBER	0.02

#elif (PHASES==2)
#warning genetic_mospk compilato per 2 fasi
#define PHASE_1 0.6

#define PHASE_0_TOTAL_COST	0.40
#define PHASE_0_VEHICLES_NUMBER	0.45

#define PHASE_1_TOTAL_COST	0.99
#define PHASE_1_VEHICLES_NUMBER	0.01

#else

//#warning genetic_mospk compilato per 3 fasi
#define PHASE_1 0.45
#define PHASE_2 0.7

#define PHASE_0_TOTAL_COST	0.90
#define PHASE_0_VEHICLES_NUMBER	0.09

#define PHASE_1_TOTAL_COST	0.85
#define PHASE_1_VEHICLES_NUMBER	0.10

#define PHASE_2_TOTAL_COST	0.99
#define PHASE_2_VEHICLES_NUMBER	0.005

#endif

#if defined LS_STR_STEEPEST_DESCENT && defined LS_STR_FIRST_IMPROVEMENT
#error Definire o Steepest descent o first improvement
#endif

#if defined LS_NEI_COMPLETE && defined LS_NEI_WIDTH
#error Definire o vicinato completo o larghezza del vicinato
#endif

#if defined LS_DEP_RECURSIVE && defined LS_NEI_MAXDEPTH
#error Definire profondita'' della ricerca locale
#endif

//! Imposta i parametri di default dell'algoritmo.
/*!
  Setta i parametri di default dell'algoritmo genetico.

  \param[out] data	Puntatore alla struttura contente i parametri
			dell'algoritmo genetico.
*/
void SetDefaults(GeneticData * data)
{
	time_t t;

//	data->DM = 0;
	data->timeLimit = -1;
	data->NumGenes = 0;
	data->CurrentGeneration = 0;
	data->People = 0;
	data->CurrentPhase = 0;
	data->class_name[0] = '\0';
	data->name_flag = 0;
	data->BestVehicleInd.Sequence = 0;
	data->TheBestOne.Sequence = 0;
	for (int p = 0; p < parameters; p++) {
		data->LB[p] = 0;
		data->UB[p] = INT_MAX;
	}

	for (int i = 0; i < times; i++) {
		data->stat.elaps[i].start = 0;
		data->stat.elaps[i].end = 0;
	}

	data->stat.generation = 0;
	data->stat.phase = 0;
	data->stat.fitness_evaluations = 0;
	data->stat.best_fitness = 0;
	data->stat.best[0] = 0;
	data->stat.best[1] = 0;
	data->stat.median_fitness = 0;
	data->stat.median[0] = 0;
	data->stat.median[1] = 0;
	data->stat.worst_fitness = 0;
	data->stat.worst[0] = 0;
	data->stat.worst[1] = 0;
	data->stat.ls_found_opt = 0;
	data->stat.last_best_generation[0] = 0;
	data->stat.last_best_generation[1] = 0;
	for (int p = 0; p < PHASES + 2; p++) {
		data->stat.best_found_at_phase[p][0] = -1;
		data->stat.best_found_at_phase[p][1] = -1;
	}
	data->stat.ls_max_depth = -1;

	if (data->seed == (unsigned)-1)
		data->seed =	// (unsigned) clock(); // (unsigned)time(&t);
		    (unsigned)time(&t);

	data->ProbMutation = data->InitialMutation;

	/*
	   data->NumIndividuals = 0;
	   data->NumGenerations = 0;
	   data->LocSearchSteepDesc = false;
	   data->Elite = 1;
	   data->SelectionRounds = 1;
	   data->FirstParent = 0.5;
	   data->LocSearchDepth = 1000000;
	   data->LocSearchFreq = 50;
	   data->LocSearchNeighWidth = 256;
	   data->LocSearchNumBestInd = 3;
	   data->LocSearchNumTotInd = 5;
	   data->PhaseHop[0] = 0.45;
	   data->PhaseHop[1] = 0.7;
	   data->Weight[0][MOS] = PHASE_0_MOS;
	   data->Weight[0][TOS] = PHASE_0_TOS;
	   data->Weight[0][NEW] = PHASE_0_NEW;
	   data->Weight[0][COM] = PHASE_0_COMMON;
	   data->Weight[0][IOS] = PHASE_0_MAX_NEW;
	   data->Weight[1][MOS] = PHASE_1_MOS;
	   data->Weight[1][TOS] = PHASE_1_TOS;
	   data->Weight[1][NEW] = PHASE_1_NEW;
	   data->Weight[1][COM] = PHASE_1_COMMON;
	   data->Weight[1][IOS] = PHASE_1_MAX_NEW;
	   data->Weight[2][MOS] = PHASE_2_MOS;
	   data->Weight[2][TOS] = PHASE_2_TOS;
	   data->Weight[2][NEW] = PHASE_2_NEW;
	   data->Weight[2][COM] = PHASE_2_COMMON;
	   data->Weight[2][IOS] = PHASE_2_MAX_NEW;
	 */
}
